//
//  MessageHeader.m
//  NewMarryU
//
//  Created by apple on 2018/7/22.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1MessageHeader.h"

@implementation M1MessageHeader
-(instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = m1_bg_color;
        UIView *m1_view = [[UIView alloc]init];
        m1_view.backgroundColor = [UIColor whiteColor];
        m1_view.layer.cornerRadius = 12;
        m1_view.layer.shadowColor = [UIColor m1_colorHex:0xCAD0DC].CGColor;
        m1_view.layer.shadowOpacity = 0.25;
        m1_view.layer.shadowOffset = CGSizeMake(1, 1);
        [self addSubview:m1_view];
        [m1_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsMake(3, 20, 3, 20));
        }];
        NSArray *m1_array = @[@"msg_fj",@"msg_wx",@"msg_pb"];
        NSArray *m1_titles = @[@"查看资料",@"换微信",@"不在看Ta"];
        float m1_with = (SCREENWIDTH - 40)/6.;
        for (int i = 0; i<3; i++) {
            UIButton *m1_btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [m1_btn setImage:[UIImage imageNamed:m1_array[i]] forState:0];
            [m1_btn setTitle:m1_titles[i] forState:0];
            [m1_btn setTitleColor:[UIColor m1_colorHex:0x999999] forState:0];
            m1_btn.titleLabel.font = m1_font(12);
            [m1_btn addTarget:self action:@selector(m1_btnClick:) forControlEvents:UIControlEventTouchUpInside];
            m1_btn.tag = i;
            [m1_btn setImageEdgeInsets:UIEdgeInsetsMake(-5, 8, 5, -8)];
            [m1_btn setTitleEdgeInsets:UIEdgeInsetsMake(30, -27, 0,0)];
            [m1_view addSubview:m1_btn];
            [m1_btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(m1_view);
                make.centerX.equalTo(m1_view.mas_left).offset(m1_with*((i+1)*2-1));
                make.size.mas_offset(CGSizeMake(50, 50));
            }];
            
            if (i>0) {
                UIView *m1_line = [[UIView alloc]init];
                m1_line.backgroundColor = [UIColor m1_colorHex:0xF0F0F0];
                [m1_view addSubview:m1_line];
                [m1_line mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.centerY.equalTo(m1_view);
                    make.centerX.equalTo(m1_view.mas_left).offset(2*i*m1_with);
                    make.size.mas_offset(CGSizeMake(0.5, 25));
                }];
            }
            
        }
    }
    return self;
}
-(void)m1_btnClick:(UIButton *)sender{
    if (_click) {
        _click(sender.tag);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
